<template>
    <div>
        <el-table :data="consultationList" border style="width: 100%">
            <el-table-column type="index" label="ID" width="50"></el-table-column>
            <el-table-column prop="title" label="问诊问题"></el-table-column>
            <el-table-column prop="isCheck" label="审核结果" width="80">
                <template slot-scope="scope">
                    {{showCheck(scope.row.isCheck)}}
                </template>
            </el-table-column>
            <el-table-column prop="isAccepted" label="接纳" width="80">
                <template slot-scope="scope">
                    <el-tag
                            v-if="scope.row.status > 0"
                            :type="tagStatus(scope.row.isAccept)"
                            size="mini">{{showAccept(scope.row.isAccept)}}</el-tag>
                    <el-tag
                            v-else
                            type="info"
                            size="mini">未确认</el-tag>
                </template>
            </el-table-column>
            <el-table-column prop="score" label="评分" width="170">
                <template slot-scope="scope">
                    <el-rate
                            v-if="scope.row.status==4"
                            v-model="scope.row.score"
                            disabled
                            show-score
                            text-color="#ff9900"
                            score-template="{value}">
                    </el-rate>
                    <el-tag
                            v-else
                            type="info"
                            size="mini">未评分</el-tag>
                </template>
            </el-table-column>
            <el-table-column prop="created_at" label="提问时间" width="170"></el-table-column>
            <el-table-column label="操作" width="90">
                <template slot-scope="scope">
                    <el-button v-if="scope.row.status > 2" @click="info(scope.row)" size="mini">查看</el-button>
                    <el-button v-else-if="scope.row.isPost && !scope.row.isCheck" type="danger" size="mini" disabled>待审核</el-button>
                    <el-button v-else-if="!scope.row.isPost && scope.row.isCheck == 1" type="danger" size="mini" @click="reply(scope.row)">修改</el-button>
                    <el-button v-else type="primary" @click="reply(scope.row)" size="mini">回答</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="margin-top-20 text-center" v-if="consultationList.length">
            <el-pagination
                    @size-change="pageSizeChange"
                    @current-change="currentPageChange"
                    :background="true"
                    :current-page="page.currentPage"
                    :page-sizes="[10, 20, 30]"
                    :page-size="page.size"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="page.total">
            </el-pagination>
        </div>
    </div>
</template>

<script>
export default {
  data() {
    return {
      consultationList: [],
      page: {
        total: 0,
        currentPage: 1,
        size: 10
      }
    };
  },
  mounted() {
    this.getConsultationInfoData();
  },
  methods: {
    getConsultationInfoData() {
      let id = this.$store.state.doctorInfo.id;

      this.axios
        .post("/doctor/" + id + "/consultations/list/text", {
          params: {
            pageSize: this.page.size,
            currentPage: this.page.currentPage,
            status: "1,2,3"
          }
        })
        .then(response => {
          if (response.data.code == 200) {
            this.consultationList = response.data.data.data;
            this.page.total = response.data.data.total;
          } else {
            this.$message({
              message: "数据加载失败!",
              type: "error"
            });
          }
        });
    },
    pageSizeChange(val) {
      this.page.currentPage = 1;
      this.page.size = val;
      this.getConsultationInfoData();
    },
    currentPageChange(val) {
      this.page.currentPage = val;
      this.getConsultationInfoData();
    },
    info(row) {
      this.$router.push({ name: "ReplyInfo", params: { consultationId: row.id } });
    },
    reply(row) {      
       this.$router.push({ name: "ReferralInfo", params: { consultationId: row.id } });
    },
    showCheck(isCheck) {
      switch (isCheck) {
        case 0:
          return "未审核";
          break;
        case 1:
          return "驳回";
          break;
        case 2:
          return "通过";
          break;
        default:
          return "无";
          break;
      }
    },
    showAccept(isAccept) {
      switch (isAccept) {
        case 0:
          return "未确认";
          break;
        case 1:
          return "不采纳";
          break;
        case 2:
          return "已采纳";
          break;
        default:
          return "无";
          break;
      }
    },
    tagStatus(status) {
      switch (status) {
        case 1:
          return "success";
          break;
        case 2:
          return "danger";
          break;
        default:
          return "info";
          break;
      }
    }
  }
};
</script>
